/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package main.LanguageResource;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 *
 * @author Isaac Osesina
 */
public class LocalPOSFactory {
    private static LocalPOSFactory singleton;
    private Map<String, LocalPOS> map = new LinkedHashMap<String, LocalPOS>();
    
    private LocalPOSFactory() {        
    }
    
    public static LocalPOSFactory getSingleton() {
        if(singleton == null)
            singleton = new LocalPOSFactory();
        return singleton;
    }
    
    
    public LocalPOS getPos(String pos) {
        LocalPOS  ee = new LocalPOSImpl(pos);
        return map.containsKey(ee.getValue()) ? ee:null;
    }
    
     public boolean containsPos(LocalPOS localPOS) {
         return map.containsKey(localPOS.getValue());
     }

    public boolean containsPos(String pos) {
        LocalPOS  ee = new LocalPOSImpl(pos);
        return map.containsKey(ee.getValue());
    }
    
    public LocalPOS addPos(LocalPOS localPOS) {
        map.put(localPOS.getValue(), localPOS);
        return localPOS;
    }
    
    public LocalPOS addPos(String pos) {
        LocalPOS  ee = new LocalPOSImpl(pos);
        map.put(ee.getValue(), ee);
        return ee;
    }
    
    public List<LocalPOS> listAll() {
        return (List) map.values();
    }
    
    public List<String> listAllValues() {
        List<String> out = new ArrayList<String>();
        for(String ee:map.keySet())
            out.add(ee);
        return out;
    }
    
    
    private class LocalPOSImpl implements LocalPOS{
    
        private final String pos;
        
        public LocalPOSImpl(String pos) {
            this.pos = pos.toUpperCase();
        }

        @Override
        public int compareTo(LocalPOS o) {
            return pos.compareTo(o.getValue());
        }
        
        @Override
        public String getValue(){
            return pos;
        }
        
        @Override
        public String toString() {
            return pos;
        }
}
    
}
